meta %>%
filter(su_blkgp == 1) %>%
select(varname, about) %>% as.list()
## $varname
## [1] "blkgroup" "county" "avgc_allblk"
## [4] "medc_allblk" "commutersInBlgr" "avgc_within40blk"
## [7] "medc_within40blk" "commuterw40blk" "avgc_25_employeesblk"
## [10] "medc_25_employeesblk" "commuter25blk" "avgc_workinRegionblk"
## [13] "medc_workinRegionblk" "commuterinRegionblk"
##
## $about
## [1] "12-digit census block group code"
## [2] "5-digit county code"
## [3] "Average \"as the crow flies\" commuting distance for all residents of the census block group"
## [4] "Median \"as the crow flies\" commuting distance for all residents of the census block group"
## [5] "The number of residents in each census block group who are represented in the data"
## [6] "Average \"as the crow flies\" commuting distance for residents of the census block group who work within 40 miles"
## [7] "Median \"as the crow flies\" commuting distance for residents of the census block group who work within 40 miles"
## [8] "The number of residents in the census block group who work within 40 miles of home"
## [9] "Average \"as the crow flies\" commuting distance for residents of the census block group who commute to a census tract that employs at least 25 residents from the region of interest"
## [10] "Median \"as the crow flies\" commuting distance for residents of the census block group who commute to a census tract that employs at least 25 residents of the region of interest"
## [11] "The number of residents in the census block group who commute to a census tract that employs at least 25 residents of the region of interest"
## [12] "Average \"as the crow flies\" commuting distance for residents of the census block group who work in the same region as where they live"
## [13] "Median \"as the crow flies\" commuting distance for residents of the census block group who work in the same region as where they live"
## [14] "The number of residents in the census block group who commute to work within the region of interest"
glimpse(lodes)
## Rows: 155
## Columns: 14
## $ blkgroup <dbl> 510030101001, 510030101002, 510030101003, 5100301…
## $ medc_allblk <dbl> 24.17281, 34.11035, 29.70686, 22.44022, 17.74491,…
## $ medc_workinRegionblk <dbl> 5.269266, 11.406913, 9.025905, 5.388651, 3.464939…
## $ medc_within40blk <dbl> 7.443729, 12.420517, 10.480196, 7.207290, 5.55071…
## $ medc_25_employeesblk <dbl> 19.67874, 25.85719, 21.31691, 16.49003, 13.16050,…
## $ commutersInBlgr <int> 822, 666, 636, 1396, 991, 706, 771, 1066, 405, 68…
## $ commuterinRegionblk <int> 576, 447, 437, 1028, 767, 531, 602, 803, 312, 507…
## $ commuterw40blk <int> 643, 497, 489, 1124, 843, 571, 637, 873, 333, 551…
## $ commuter25blk <int> 750, 615, 583, 1299, 941, 659, 730, 1001, 380, 63…
## $ avgc_allblk <dbl> 26.56419, 32.68364, 29.94505, 22.19963, 16.95999,…
## $ avgc_workinRegionblk <dbl> 5.248561, 11.585876, 8.421038, 6.016676, 3.582384…
## $ avgc_within40blk <dbl> 7.401903, 12.448308, 10.004912, 7.713104, 5.54740…
## $ avgc_25_employeesblk <dbl> 18.84796, 27.83559, 22.77203, 17.17362, 13.14508,…
## $ county <int> 51003, 51003, 51003, 51003, 51003, 51003, 51003, …
lodes %>% select(avgc_allblk, avgc_within40blk, avgc_25_employeesblk, avgc_workinRegionblk) %>%
select(where(~is.numeric(.x))) %>%
as.data.frame() %>%
stargazer(., type = "text", title = "Summary Statistics", digits = 2,
summary.stat = c("mean", "sd", "min", "median", "max"))
##
## Summary Statistics
## ======================================================
## Statistic Mean St. Dev. Min Median Max
## ------------------------------------------------------
## avgc_allblk 25.39 8.69 13.25 24.31 78.38
## avgc_within40blk 9.13 5.10 3.07 7.39 22.56
## avgc_25_employeesblk 19.89 7.67 9.36 18.78 64.84
## avgc_workinRegionblk 7.71 5.91 1.36 5.33 24.26
## ------------------------------------------------------
long <- lodes %>% select(c(blkgroup, avgc_allblk, avgc_within40blk, avgc_25_employeesblk, avgc_workinRegionblk, medc_allblk, medc_within40blk, medc_25_employeesblk, medc_workinRegionblk)) %>%
pivot_longer(-blkgroup, names_to = "measure", values_to = "value")
long$measure <- factor(long$measure,
levels = c("avgc_allblk", "medc_allblk", "avgc_within40blk", "medc_within40blk", "avgc_25_employeesblk", "medc_25_employeesblk", "avgc_workinRegionblk",
"medc_workinRegionblk"))
long %>%
ggplot(aes(x = value, fill = measure)) +
scale_fill_viridis(option = "plasma", discrete = TRUE, guide = FALSE) +
geom_histogram() +
facet_wrap(~measure, scales = "free", ncol = 2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
meta %>%
filter(varname %in% c("avgc_allblk", "avgc_within40blk", "avgc_25_employeesblk", "avgc_workinRegionblk")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_allblk: Average "as the crow flies" commuting distance for all residents of the census block group"
[2] "avgc_within40blk: Average "as the crow flies" commuting distance for residents of the census block group who work within 40 miles"
[3] "avgc_25_employeesblk: Average "as the crow flies" commuting distance for residents of the census block group who commute to a census tract that employs at least 25 residents from the region of interest" [4] "avgc_workinRegionblk: Average "as the crow flies" commuting distance for residents of the census block group who work in the same region as where they live"
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodes$avgc_allblk)
leaflet(cvl_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodes,
fillColor = ~pal(avgc_allblk),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodes$blkgroup, "<br>",
"Average commute (mi): ", round(cvl_lodes$avgc_allblk, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodes$avgc_allblk,
title = "Average commute (mi)", opacity = 0.7)
meta %>%
filter(varname %in% c("avgc_allblk")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_allblk: Average "as the crow flies" commuting distance for all residents of the census block group"
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodes$avgc_within40blk)
leaflet(cvl_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodes,
fillColor = ~pal(avgc_within40blk),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodes$blkgroup, "<br>",
"Average commute (mi): ", round(cvl_lodes$avgc_within40blk, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodes$avgc_within40blk,
title = "Average commute (mi)", opacity = 0.7)
meta %>%
filter(varname %in% c("avgc_within40blk")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_within40blk: Average "as the crow flies" commuting distance for residents of the census block group who work within 40 miles"
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodes$avgc_25_employeesblk)
leaflet(cvl_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodes,
fillColor = ~pal(avgc_25_employeesblk),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodes$blkgroup, "<br>",
"Average commute (mi): ", round(cvl_lodes$avgc_25_employeesblk, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodes$avgc_25_employeesblk,
title = "Average commute (mi)", opacity = 0.7)
meta %>%
filter(varname %in% c("avgc_25_employeesblk")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_25_employeesblk: Average "as the crow flies" commuting distance for residents of the census block group who commute to a census tract that employs at least 25 residents from the region of interest"
pal <- colorNumeric("plasma", reverse = T, domain = cvl_lodes$avgc_workinRegionblk)
leaflet(cvl_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvl_lodes,
fillColor = ~pal(avgc_workinRegionblk),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", cvl_lodes$blkgroup, "<br>",
"Average commute (mi): ", round(cvl_lodes$avgc_workinRegionblk, 2))) %>%
addLegend("bottomright", pal = pal, values = cvl_lodes$avgc_workinRegionblk,
title = "Average commute (mi)", opacity = 0.7)
meta %>%
filter(varname %in% c("avgc_workinRegionblk")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_workinRegionblk: Average "as the crow flies" commuting distance for residents of the census block group who work in the same region as where they live"